<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

abstract class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    protected $data;

    function __construct() {
        $this->data['title'] = 'Undefined Title';
    }

    /**
     * @param null $redirect
     * @param string $info
     * @param int $type 1.成功；2.失败；3.信息
     * @return array
     */
    protected function _message($redirect = NULL, $info = '操作成功', $type = 1) {
        return [
            'type' => $type,
            'info' => $info,
            'redirect' => $redirect
        ];
    }

    /**
     * @param null $redirect
     * @param string $info
     * @return array
     */
    protected function _success($redirect = NULL, $info = '操作成功') {
        return $this->_message($redirect, $info, 1);
    }

    /**
     * @param null $redirect
     * @param string $info
     * @return array
     */
    protected function _error($redirect = NULL, $info = '操作失败') {
        return $this->_message($redirect, $info, 2);
    }
}
